import { _decorator, Component, director, Button } from 'cc'
import { DialogDef, UIManager } from './UIManager'
const { ccclass, property } = _decorator

@ccclass('UIGame')
export class UIGame extends Component {
    start() {
        const exit = this.node.getChildByPath('BtnLayout/BtnExit')
        const setting = this.node.getChildByPath('BtnLayout/BtnSetting')
        const pause = this.node.getChildByPath('BtnLayout/BtnPause')

        exit.on(Button.EventType.CLICK, this.onExitGame, this)
        setting.on(Button.EventType.CLICK, this.onOpenSetting, this)
        pause.on(Button.EventType.CLICK, this.onPauseGame, this)
    }

    update(deltaTime: number) {
        
    }

    private onExitGame() {
        director.loadScene('start')
        UIManager.instance.clearAllPanels()
    }

    private onPauseGame() {
        director.isPaused() ? director.resume() : director.pause()
    }

    private onOpenSetting() {
        UIManager.instance.openDialog(DialogDef.UISETTING)
    }
}


